package com.cwm.hystrix;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class ProducerService {
    private final StreamBridge streamBridge;

    /**
     * * 生产消息
     *
     * @param msg
     */
    @HystrixCommand(fallbackMethod= "errMethod")
    public void sendMsg(String msg) {
        int i = 1/0;
        System.out.println("------生产消息------");
        streamBridge.send("source-out-0", msg);
    }

    /**
     * 调用服务异常执行方法
     * */
    private void errMethod(String msg){
        log.info("熔断,调用sendMsg服务发生异常");
        /**后续流程处理*/
//        return "";
    }

}
